﻿using System;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;

namespace Range_Pinger
{
    public partial class ConvertAddress : Form
    {
        public ConvertAddress()
        {
            InitializeComponent();
        }

        private void btnDNStoIP_Click(object sender, EventArgs e)
        {
            try
            {
                IPAddress[] addresslist = Dns.GetHostAddresses(txtAddress.Text);

                foreach (IPAddress theaddress in addresslist)
                {
                    txtConverted.Text = theaddress.ToString();
                }
            }
            catch
            {
                txtConverted.Text = "Address doesn't exist or isn't valid";
            }
        }

        private void btnIPtoDNS_Click(object sender, EventArgs e)
        {
            try
            {
                IPHostEntry IpToDomainName = Dns.GetHostEntry(txtAddress.Text);
                txtConverted.Text = IpToDomainName.HostName;
            }
            catch
            {
                txtConverted.Text = "Address doesn't exist or isn't valid";
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
